package flc.ast.fragment;


import android.content.Intent;
import android.view.View;

import androidx.fragment.app.Fragment;


import com.youth.banner.listener.OnBannerListener;
import com.youth.banner.listener.OnPageChangeListener;

import java.util.ArrayList;
import java.util.List;

import flc.ast.bean.MyBannerBean;
import flc.ast.R;
import flc.ast.activity.SelPicActivity;
import flc.ast.adapter.MyBannerAdapter;
import flc.ast.databinding.FragmentHomeBinding;
import flc.ast.utils.Content;
import stark.common.basic.base.BaseNoModelFragment;
import stark.common.basic.event.EventStatProxy;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link HomeFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class HomeFragment extends BaseNoModelFragment<FragmentHomeBinding> {


    @Override
    protected int onCreate() {
        return R.layout.fragment_home;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent1(getActivity(), mDataBinding.event1Container);
        EventStatProxy.getInstance().statEvent5(getActivity(), mDataBinding.event5Container);
        mDataBinding.ivHomeSplitShu.setOnClickListener(this);
        mDataBinding.ivHomeSplitZy.setOnClickListener(this);
        mDataBinding.ivHomeSplitHeng.setOnClickListener(this);
        List<MyBannerBean> listBanner = new ArrayList<>();
        listBanner.add(new MyBannerBean(R.drawable.fx1,getString(R.string.type_text1)));
        listBanner.add(new MyBannerBean(R.drawable.sx1,getString(R.string.type_text3)));
        listBanner.add(new MyBannerBean(R.drawable.zy1,getString(R.string.type_text2)));
        MyBannerAdapter bannerAdapter = new MyBannerAdapter(listBanner);
        mDataBinding.homeBanner.setAdapter(bannerAdapter, true);//false不无限循环
        mDataBinding.homeBanner.setBannerGalleryEffect(60, 10);//40两边露出距离，20图片之间距离
        mDataBinding.homeBanner.isAutoLoop(false);//false不自动轮播
        //点击监听
        mDataBinding.homeBanner.setOnBannerListener(new OnBannerListener() {
            @Override
            public void OnBannerClick(Object data, int position) {
                if (position==0){
                    gotoSelPic(Content.Split_Zy_Fx);
                }else if (position==1){
                    gotoSelPic(Content.Split_Zy_Sx);
                }else {
                    gotoSelPic(Content.Split_Zy_Zy);
                }
            }
        });
        mDataBinding.homeBanner.addOnPageChangeListener(new OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                mDataBinding.tvBannerItemText.setText(listBanner.get(position).getText());
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
        mDataBinding.homeBanner.start();
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()){
            case R.id.ivHomeSplitShu://拼接-竖
                gotoSelPic(Content.Split_Shu);
                break;
            case R.id.ivHomeSplitZy://拼接-自由
                gotoSelPic(Content.Split_Zy);
                break;
            case R.id.ivHomeSplitHeng://拼接-横
                gotoSelPic(Content.Split_Heng);
                break;
        }
    }

    @Override
    protected void initData() {

    }

    //去到选择图片界面
    private void gotoSelPic(String flag) {
        Intent intent = new Intent(mContext, SelPicActivity.class);
        intent.putExtra(Content.Flag, flag);
        startActivity(intent);
    }

}